﻿using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

public class GameSettingP : MonoBehaviour
{
    [SerializeField] TMP_Dropdown dropdown;
    [SerializeField] TextMeshProUGUI fullScreen;
    [SerializeField] Slider slider;
    [SerializeField] Slider slider_B;
    [SerializeField] TextMeshProUGUI dropdownLabe;
    AudioSource audio;

    public void Start()
    {
        audio = GetComponent<AudioSource>();
        audio.volume = SaveData._.BGMSize;

        dropdown.value = SaveData._.Size;
        ChangeSize();

        if (Screen.fullScreen!=SaveData._.fullScreen)
        {
            FullScreen();
        }

        if (Screen.fullScreen)
        {
            fullScreen.text = Language.Get("取消全屏"); 
        }
        else
        {
            fullScreen.text = Language.Get("开启全屏");
        }
        

        slider.value = SaveData._.muiscSize;
    }

    public void ChangeSize()
    {
        switch (dropdown.value)
        {
            case 0:
                Screen.SetResolution(800, 600,Screen.fullScreenMode);
                break;
            case 1:
                Screen.SetResolution(1280, 720,Screen.fullScreenMode);
                break;
            case 2:
                Screen.SetResolution(1440, 900,Screen.fullScreenMode);
                break;
            case 3:
                Screen.SetResolution(1920, 1080,Screen.fullScreenMode);
                break;
            case 4:
                Screen.SetResolution(2560, 1440, Screen.fullScreenMode);
                break;
            default:
                break;
        }
        Debug.Log(dropdown.value);
        SaveData._.Size = dropdown.value;
        SaveData.Save();

        slider.value = SaveData._.muiscSize;
        slider_B.value = SaveData._.BGMSize;

        dropdownLabe.text = Language.Get(dropdownLabe.text);
    }

    public void FullScreen()
    {
        bool newFull = !Screen.fullScreen;
        Screen.SetResolution(Screen.width, Screen.height, newFull);
        if (newFull)
        {
            fullScreen.text = Language.Get("取消全屏");
        }
        else
        {
            fullScreen.text = Language.Get("开启全屏");
        }
        SaveData._.fullScreen = newFull;
        SaveData.Save();
    }

    public void VChange()
    {
        SaveData._.muiscSize = slider.value;
        SaveData.Save();
    }    
    
    public void BChange()
    {
        SaveData._.BGMSize = slider_B.value;
        audio.volume = SaveData._.BGMSize;
        SaveData.Save();
    }
}
